package com.mephi.oshs.view.impl;

import com.mephi.oshs.model.entry.IEntry;
import com.mephi.oshs.view.api.IOshsView;
import com.mephi.oshs.view.api.ViewId;
import com.mephi.oshs.view.elements.Clickable;
import com.mephi.oshs.view.elements.IOshsTreeWidget;
import com.mephi.oshs.view.elements.Textable;
import com.mephi.oshs.view.lang.Labels;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

import static com.mephi.oshs.view.impl.GridLayoutManager.*;

public class OshsView extends AbstractView implements IOshsView {

    private Button quickSearchButton;
    private Text quickSearchText;
    private IOshsTreeWidget<IEntry> tree;

    public void createGUI() {
        parent.setLayout(getGridLayout());

        final Label label = new Label(parent, SWT.NONE);
        label.setLayoutData(getLayoutDataFillHorizontal());

        label.setText(TEXT_MANAGER.getText(Labels.OSHS_VIEW_QUICK_SEARCH_LABEL));

        final Text text = new Text(parent, SWT.BORDER);
        text.setLayoutData(getLayoutDataFillHorizontal());

        this.quickSearchText = text;

        final Button button = new Button(parent, SWT.NONE);
        button.setLayoutData(getLayoutDataFillHorizontal());
        button.setText(TEXT_MANAGER.getText(Labels.OSHS_VIEW_QUICK_SEARCH_ACTION));

        this.quickSearchButton = button;

        this.tree = this.constructTree(parent);
    }

    private IOshsTreeWidget<IEntry> constructTree(final Composite composite) {
        final IOshsTreeWidget<IEntry> tree = new EntryTree<IEntry>(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        ((Control) tree).setLayoutData(getLayoutDataFillAll());
        return tree;
    }

    @Override
    public Clickable getQuickSearchAction() {
        return new Clickable(quickSearchButton);
    }

    @Override
    public Textable getQuickSearchText() {
        return new Textable(this.quickSearchText);
    }

    @Override
    public IOshsTreeWidget<IEntry> getOshsTreeWidget() {
        return this.tree;
    }

    @Override
    public ViewId getViewID() {
        return ID;
    }
}
